* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: Arial, sans-serif;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background-color: #faf8ef;
  padding: 20px;
}

.container {
  width: 100%;
  max-width: 500px;
  text-align: center;
}

h1 {
  color: #776e65;
  font-size: min(48px, 10vw);
  margin-bottom: 20px;
}

.score-container {
  font-size: min(24px, 5vw);
  color: #776e65;
  margin-bottom: 20px;
  display: flex;
  justify-content: center;
  gap: 20px;
}

.score-box {
  background: #bbada0;
  padding: 10px 20px;
  border-radius: 6px;
  color: white;
}

.score-box .label {
  font-size: min(16px, 3.5vw);
  text-transform: uppercase;
}

.score-box .value {
  font-size: min(24px, 5vw);
  font-weight: bold;
}

.grid-container {
  background-color: #bbada0;
  padding: 3.5%;
  border-radius: 6px;
  margin-bottom: 20px;
  width: 100%;
}

.grid-row {
  display: flex;
  margin-bottom: 3.5%;
}

.grid-row:last-child {
  margin-bottom: 0;
}

.grid-cell {
  width: 22.75%;
  margin-right: 3.5%;
  background-color: rgba(238, 228, 218, 0.35);
  border-radius: 3px;
  font-weight: bold;
  color: #776e65;
  position: relative;
}

.grid-cell:last-child {
  margin-right: 0;
}

.grid-cell::before {
  content: '';
  display: block;
  padding-top: 100%;
}

.grid-cell span {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: min(36px, 7vw);
  width: 100%;
  text-align: center;
}

.grid-cell[data-value="2"] {
  background-color: #eee4da;
}

.grid-cell[data-value="4"] {
  background-color: #ede0c8;
}

.grid-cell[data-value="8"] {
  background-color: #f2b179;
  color: #f9f6f2;
}

.grid-cell[data-value="16"] {
  background-color: #f59563;
  color: #f9f6f2;
}

.grid-cell[data-value="32"] {
  background-color: #f67c5f;
  color: #f9f6f2;
}

.grid-cell[data-value="64"] {
  background-color: #f65e3b;
  color: #f9f6f2;
}

.grid-cell[data-value="128"] {
  background-color: #edcf72;
  color: #f9f6f2;
}

.grid-cell[data-value="256"] {
  background-color: #edcc61;
  color: #f9f6f2;
}

.grid-cell[data-value="512"] {
  background-color: #edc850;
  color: #f9f6f2;
}

.grid-cell[data-value="1024"] {
  background-color: #edc53f;
  color: #f9f6f2;
}

.grid-cell[data-value="2048"] {
  background-color: #edc22e;
  color: #f9f6f2;
}

.grid-cell[data-value="4096"] {
  background-color: #3c3a32;
  color: #f9f6f2;
}

.grid-cell[data-value="8192"] {
  background-color: #ff5722;
  color: #f9f6f2;
}

.grid-cell[data-value="16384"] {
  background-color: #ff9800;
  color: #f9f6f2;
}

.grid-cell[data-value="32768"] {
  background-color: #ffc107;
  color: #f9f6f2;
}

.grid-cell[data-value="65536"] {
  background-color: #ffeb3b;
  color: #f9f6f2;
}

.grid-cell[data-value="128"] span,
.grid-cell[data-value="256"] span,
.grid-cell[data-value="512"] span {
  font-size: min(32px, 6vw);
}

.grid-cell[data-value="1024"] span,
.grid-cell[data-value="2048"] span,
.grid-cell[data-value="4096"] span {
  font-size: min(28px, 5vw);
}

.grid-cell[data-value="8192"] span,
.grid-cell[data-value="16384"] span,
.grid-cell[data-value="32768"] span,
.grid-cell[data-value="65536"] span {
  font-size: min(24px, 4vw);
}

.grid-cell {
  transition: transform 0.15s ease-in-out, background-color 0.15s ease-in-out;
}

.grid-cell.new-tile {
  animation: appear 0.2s ease-in-out;
}

.grid-cell.merged-tile {
  animation: pop 0.2s ease-in-out;
}

@keyframes appear {
  0% {
    opacity: 0;
    transform: scale(0);
  }

  100% {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes pop {
  0% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.1);
  }

  100% {
    transform: scale(1);
  }
}

.button-container {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin-top: 20px;
}

button {
  background-color: #8f7a66;
  color: white;
  border: none;
  border-radius: 3px;
  padding: 10px 20px;
  font-size: min(18px, 4vw);
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color 0.2s ease;
}

button:hover {
  background-color: #9f8b77;
}

button:active {
  transform: scale(0.95);
}

@media (max-width: 500px) {
  body {
    padding: 10px;
  }

  .container {
    margin: 0 auto;
  }
}